package com.ttc.mBackup.BackupImages;

import java.util.ArrayList;


import com.ttc.mBackup.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;


import android.widget.LinearLayout;
import android.widget.TextView;


public class CustomListAdapter extends BaseAdapter {

	ArrayList<String> listContent;
	Context context;
	public int selectedIndex = 0;
	
	
	
	public int getSelectedIndex() {
		return selectedIndex;
	}

	public void setSelectedIndex(int selectedIndex) {
		this.selectedIndex = selectedIndex;
	}

	public CustomListAdapter(ArrayList<String> listContent, Context context) {
		super();
		this.listContent = listContent;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listContent.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return listContent.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		if (convertView == null) {
			convertView = new CustomListItem(context);
		}

		final String item = listContent.get(position);

		if (convertView != null) {
			//ImageView icon = ((CustomListItem) convertView).getIcon();
			TextView content = ((CustomListItem) convertView)
					.getContent();
			content.setText(item);

		}
		LinearLayout linear = ((CustomListItem) convertView).getLinear();
		//highlight selected row
		if(position == selectedIndex){
			
			linear.setBackgroundResource(R.color.highlight_row);
		}
		else{
			linear.setBackgroundResource(R.color.transparent);
		}
		
		return convertView;
	}

}
